<template>
	<view>
		<view class="flexcolumn" v-if="list.data.length==0">
			<view class="placeholderimage" style="margin-top: 200rpx;"></view>
			<view class="xiaohei textcenter ershil">很抱歉，您还没有购票暂时没有出行订单！<text class="xiaolan" @click="goupiao">去购票</text>
			</view>
		</view>
		<view class="mainpadding2" v-else>
			<view class="mainpadding_top ffffff radius" @click="jumpdetail('/pages/mine/dingdanxq?id=',item.id)"
				v-for="item in list.data" :key="item.id">
				<view class="xiaolan sanshier">{{item.tourist_name}}</view>
				<view class="flexbetween margin_top">
					<view class="xiaohei fonweight ershiba">{{item.cc_time_text}} {{item.start_tourist_site_time}}出发</view>
					<!-- 1=待支付,2=待乘车,3=已完成,4=取消审核中,5=已取消 -->
					<view class="xiaohong ershil" v-if="item.state==1">待支付</view>
					<view class="xiaolan ershil" v-if="item.state==2">待出行</view>
					<view class="xiaolv ershil" v-if="item.state==3">已完成</view>
					<view class="xiaohuang ershil" v-if="item.state==4">取消审核中</view>
					<view class="xiaohui ershil" v-if="item.state==5">已取消</view>
				</view>
				<view class="xiahuaxian">
					<view class="margin_top">
						<text class="lvdian margin_right2"></text>
						<text class="xiaohui ershiba ">{{item.start_tourist_site_time}}  {{item.start_tourist_site_name}}</text>
					</view>
					<view class="margin_top">
						<text class="huangdian margin_right2"></text>
						<text class="xiaohui ershiba ">{{item.end_tourist_site_time}}  {{item.end_tourist_site_name}}</text>
					</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="xiaohei fonweight ershil">{{item.order_no}}</view>
					<view class="flexright">
						<view class="listbaibtn strongtext margin_left3 xiaohui" v-if="item.state==1 || item.state==2"
							@click.stop="cancelOrder(item.id)">取消订单</view>
						<view class="listlanbtn strongtext margin_left3 xiaobai" v-if="item.state==1"
							@click.stop="pay(item)">立即支付</view>
						<view class="listbaibtn strongtext margin_left3 xiaohui" v-if="item.state==3 || item.state==5"
							@click.stop="delOrder(item.id)">删除订单</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				tabsid: 0,
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				is_login:false
			}
		},
		onShow() {
			this.is_login = httpRequest.checkIsLogin();
			if (this.is_login) {
				this.init()
			} else {
				this.page = 1
				this.page = 12
				this.list = {
					data: []
				}
			}
		},
		methods: {
			cancelOrder(id) {
				httpRequest.modal('提示', '是否确认取消订单', true, (resp) => {
					if (resp) {
						httpRequest.request("/api/Travelcl/cancelOrder", 'POST', {
							order_id: id
						}).then(res => {
							httpRequest.toast(res.msg)
							if (res.code == 1) {
								this.init()
							}
						})
					}
				})
			},
			delOrder(id) {
				httpRequest.modal('提示', '是否确认删除订单', true, (resp) => {
					if (resp) {
						httpRequest.request("/api/Travelcl/delOrder", 'POST', {
							id
						}).then(res => {
							httpRequest.toast(res.msg)
							if (res.code == 1) {
								this.init()
							}
						})
					}
				})
			},
			pay(item) {
				uni.navigateTo({
					url: "/pages/index/zhifu?order_id=" + item.id + "&pay_price=" + item.pay_price
				})
			},
			init(isPage, page) {
				let _this = this
				httpRequest.request('/api/Travelcl/getorderlist', 'GET', {
					page: page || 1,
					limit: 12,
					// 0=全部，1=待支付,2=待乘车,3=已完成,4=取消审核中,5=已取消
					state: this.tabsid
				}).then(res => {
					uni.stopPullDownRefresh()
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			changetab(e) {
				this.tabsid = e.value
				this.list.records = []
				this.init()
			},
		}
	}
</script>

<style>

</style>